<template>
  <div class="content-item">
    <TableModel :table-data="checkList" :loading="loading" :is-show-select=false>
      <el-table-column prop="sectionType" label="班次名称">
        <template slot-scope="scope">
          <span>{{ scope.row.sectionType == 1 ? "白班" : "晚班" }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="bidSectionName" label="标段"></el-table-column>
      <el-table-column prop="workAreaName" label="所属工区"></el-table-column>
      <el-table-column prop="startsignin" label="开始签到"></el-table-column>
      <el-table-column prop="dutystarttime" label="上班时间"></el-table-column>
      <el-table-column prop="endsignin" label="签到结束"></el-table-column>
      <el-table-column prop="earlyofftime" label="早退计时"></el-table-column>
      <el-table-column prop="dutyendtime" label="下班时间"></el-table-column>
      <el-table-column prop="signouttime" label="签退结束"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="text" size="small" @click="delCheckInfo(scope.row.sectionid)">删除</el-button>
        </template>
      </el-table-column>
    </TableModel>
  </div>
</template>

<script>
import HttpInterface from "../../../util/httpInterface";
import TableModel from "../../models/TableModel";
import { messageBox } from "../../../util/utils";
import { mapState } from "vuex";

export default {
  name: "CheckList",
  components: { TableModel },
  data() {
    return {
      loading: false,
      checkList: [],
    };
  },

  computed: {
    ...mapState(["biaoduanList", "workAreaList"])
  },

  methods: {
    handleEdit(row) {
      this.$emit("modifCheck", row.sectionid)
    },

    getCheckList () {
      this.loading = true;
      let _this = this;
      let { biaoduanList } = this;
      HttpInterface.requestGet(this, HttpInterface.URL_DUTYSECTION_LIST, {}, function (response) {
        var { data } = response.data;
        data.forEach(item => {
          let str = "";
          biaoduanList.forEach(key => {
            if (item.bidSection == key.id) item.bidSectionName = key.name;
          })

          if (item.workAreaList && item.workAreaList.length > 0) {
            item.workAreaList.forEach(key => {
              str += key.name + "、";
            })
            item.workAreaName = str.slice(0, -1);
          }
        })
        _this.checkList = data.reverse();
        _this.loading = false;
      }, null)
    },

    delCheckInfo(id) {
      let _this = this;
      messageBox(() => {
        let params = { id };
        HttpInterface.requestGet(this, HttpInterface.URL_DUTYSECTION_DEL, params, res => {
          let { success } = res.data;
          if (success) {
            _this.successMessage("删除成功");
            _this.getCheckList();
          } else {
            _this.errorMessage("删除失败");
          }
        })
      })
    }
  }
};
</script>
